package com.ftd.action;

import com.ftd.config.PageType;
import com.ftd.config.ResultType;
import com.ftd.dao.UserDao;
import com.ftd.daoImp.UserDaoImp;
import com.opensymphony.xwork2.ActionSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.test.context.ContextConfiguration;

import javax.annotation.Resource;

@Component
public class UserAction extends ActionSupport {

	private String userPhone;
	private String userPassword;
	private String userEmail;
	private String errorMsg;

	@Resource(name = "UserDaoImp")
	private UserDao userDao;

	public String login(){
		ResultType resultType = userDao.login(userPhone,userPassword);
		if (resultType.getIndex() == 0){
			errorMsg = null;
			return PageType.图书列表.getName();
		} else {
			errorMsg = resultType.getName();
			return PageType.登录.getName();
		}
	}

	public String register() {
		ResultType resultType = userDao.register(userPhone, userPassword, userEmail);
		if (resultType.getIndex() == 0) {
			errorMsg = null;
			return PageType.登录.getName();
		} else {
			errorMsg = resultType.getName();
			return PageType.注册.getName();
		}
	}

	public String getUserPhone() {
		return userPhone;
	}

	public void setUserPhone(String userPhone) {
		this.userPhone = userPhone;
	}

	public String getUserPassword() {
		return userPassword;
	}

	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}


	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public String getUserEmail() {
		return userEmail;
	}

	public void setUserEmail(String userEmail) {
		this.userEmail = userEmail;
	}

	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}
}